class Admin::GuestBooksController < Admin::ApplicationController
  before_action :set_guest_book, only: [:show, :edit, :update, :destroy]

  # GET /admin/guest_books
  def index
    @guest_books = GuestBook.where(admin_user_id: current_admin_user_id).page(params[:page]).per(10)
  end

  # GET /admin/guest_books/1
  def show
  end

  # GET /admin/guest_books/new
  def new
    @guest_book = GuestBook.new
  end

  # GET /admin/guest_books/1/edit
  def edit
  end

  # POST /admin/guest_books
  def create
    @guest_book = GuestBook.new(guest_book_params)

    if @guest_book.save
      redirect_to [:admin, @guest_book], notice: 'Guest book was successfully created.'
    else
      render :new
    end
  end

  # PATCH/PUT /admin/guest_books/1
  def update
    if @guest_book.update(guest_book_params)
      redirect_to [:admin, @guest_book], notice: 'Guest book was successfully updated.'
    else
      render :edit
    end
  end

  # DELETE /admin/guest_books/1
  def destroy
    @guest_book.destroy
    redirect_to admin_guest_books_url, notice: 'Guest book was successfully destroyed.'
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_guest_book
      @guest_book = GuestBook.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def guest_book_params
      params.require(:guest_book).permit(:phone, :e_mail, :name, :content, :admin_user_id, :deleted_at)
    end
end
